package com.lzy.controller;

import java.util.Arrays;
import java.util.Map;

import com.lzy.annotation.Log;
import com.lzy.common.R;
import com.lzy.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.lzy.entity.SysLogininforEntity;
import com.lzy.service.ISysLogininforService;

/**
 * 系统访问记录
 *
 * @author lyw
 * @email lyw@gmail.com
 * @date 2023-02-03 11:26:39
 */
@Api(tags = "用户模块")
@RestController
@RequestMapping("/syslogininfor")
public class SysLogininforController {
    @Autowired
    private ISysLogininforService ISysLogininforService;

    /**
     * 列表
     */
    @Log(title = "用户模块", businessType = BusinessType.LOGIN, isSaveRequestParams = true)
    @ApiOperation(value = "用户列表")
    @PostMapping("/list")
    public R list(@RequestParam(value = "page", defaultValue = "1") Integer page,
                  @RequestParam(value = "limit", defaultValue = "10") Integer limit){
        Page<Map<String, Object>> result = new Page<>(page, limit);
        LambdaQueryWrapper<SysLogininforEntity> lqw = new LambdaQueryWrapper<>();
        IPage<Map<String, Object>> list = ISysLogininforService.selectPageList(result, lqw);
        return R.ok().put("page", list);
    }


    /**
     * 信息
     */
    @Log(title = "用户模块", businessType = BusinessType.INFO)
    @ApiOperation(value = "用户信息")
    @GetMapping("/info/{infoId}")
    public R info(@PathVariable("infoId") Long infoId){
		    SysLogininforEntity sysLogininfor = ISysLogininforService.getById(infoId);
        return R.ok().put("sysLogininfor", sysLogininfor);
    }

    /**
     * 保存
     */
    @Log(title = "用户模块", businessType = BusinessType.INSERT)
    @ApiOperation(value = "保存用户")
    @PostMapping("/save")
    public R save(@RequestBody SysLogininforEntity sysLogininfor){
		    ISysLogininforService.save(sysLogininfor);
        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新用户")
    @Log(title = "用户模块", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R update(@RequestBody SysLogininforEntity sysLogininfor){
		    ISysLogininforService.updateById(sysLogininfor);
        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除用户")
    @Log(title = "用户模块", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] infoIds){
		    ISysLogininforService.removeByIds(Arrays.asList(infoIds));
        return R.ok();
    }

}
